package com.meteor.downloader.videodownloader.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.meteor.downloader.videodownloader.databinding.ItemLanguageSetItemBinding
import com.meteor.downloader.videodownloader.mdmdata.DataMdmLanguage

class AdapterLanguageSetItem(
    private val mAdapterContext: Context,
    private val mListDoData: MutableList<DataMdmLanguage>,
    private val clickItem: (Int) -> Unit
) :
    RecyclerView.Adapter<AdapterLanguageSetItem.HolderItem>() {
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): HolderItem {
        val binding = ItemLanguageSetItemBinding.inflate(
            LayoutInflater.from(mAdapterContext),
            parent,
            false
        )
        val holderItem = HolderItem(binding)
        holderItem.itemView.setOnClickListener {
            clickItem(holderItem.absoluteAdapterPosition)
        }
        return holderItem
    }

    override fun onBindViewHolder(
        holder: HolderItem,
        position: Int
    ) {
        val data = mListDoData[position]
        holder.mMdmBinding.apply {
            tvLanguageName.text = data.mdmName
            holder.itemView.isSelected = data.fingerSelect
        }
    }

    override fun getItemCount(): Int {
        return mListDoData.size
    }

    inner class HolderItem(val mMdmBinding: ItemLanguageSetItemBinding) :
        RecyclerView.ViewHolder(mMdmBinding.root)

}